package handle

import (
	"context"
	"week1zk-project/api/pkg"
	pb "week1zk-project/user-rpc/api/user"
	"week1zk-project/user-rpc/internal/model"
)

func (s *UserInfoService) UserLogin(ctx context.Context, req *pb.UserLoginRequest) (resp *pb.UserLoginResponse, err error) {
	u := model.User{
		Username: req.Username,
		Password: pkg.Md5(req.Password),
		Email:    req.Email,
	}
	err = u.Login(u.Username, u.Password)
	if err != nil {
		return &pb.UserLoginResponse{
			Code: 400,
			Msg:  "登录失败",
		}, err
	}
	return &pb.UserLoginResponse{
		Code:   200,
		Msg:    "登录成功",
		UserId: int64(u.ID),
	}, nil
}
